package com.ming.user.service.impl;

import java.util.List;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.ming.core.db.JdbcUtils;
import com.ming.user.dao.UserDao;
import com.ming.user.entity.User;
import com.ming.user.service.UserService;
import com.ming.user.test.TestDaoInjection;

@Singleton
public class UserServiceImpl implements UserService {
	
	
	@Inject
	private UserDao userDao;
	
	@Inject
	private TestDaoInjection testDao;

	
	
	@Override
	public void add(User u) throws Exception {
		try {
			userDao.add(u.getAccount(), u.getUser_id());
			JdbcUtils.commit();
		}catch(Exception e){
			JdbcUtils.rollback();
			throw e;
		} finally {
			JdbcUtils.close();
		}
		
	}
	
	@Override
	public void test(){
		testDao.test();
	}

	@Override
	public void addTwoUser(List<User> ulist) throws Exception {
		for(User u : ulist){
			add(u);
		}
		userDao.addTest();
		
	}
}
